home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5448 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: mail2news.demon.co.uk!ues5.cern.ch
  2. From: Dan Pop <Dan.Pop@cern.ch>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Function pointers in C -- HELP!
  5. Date: Mon, 12 Feb 1996 21:31:26 +0100
  6. Organization: CERN European Lab for Particle Physics
  7. Message-ID: <9602122031.AA07749@ues5.cern.ch>
  8. References: <311F8FE4.C99@dimensional.com>
  9. X-NNTP-Posting-Host: ues5.cern.ch
  10. X-Newsreader: NN version 6.5.0 #7 (NOV)
  11. X-Mail2News-Path: mail1.cern.ch!ues5.cern.ch
  12.  
  13. Eric Seale <seale@dimensional.com> writes:
  14.  
  15. >Every compiler I've tried barfs on the indicated line in this
  16. >code.  I can't see what I'm doing wrong -- can somebody lend me a
  17. >hand (the compilers seem to dislike the "(ID)")?
  18. >
  19. >   #include <stdio.h>
  20. >
  21. >   void ptr_test(void);
  22. >   int test_entry_1(int);
  23.     ^^^
  24. This declaration is in open conflict with the definition of test_entry_1.
  25.  
  26. >   void ptr_test()    {
  27. >   int        *funct_ptr;
  28.  
  29. Either I'm a complete idiot or funct_ptr is declared as a pointer to int.
  30.  
  31. >   int            ID;
  32. >
  33. >       funct_ptr    = (int *)test_entry_1;
  34.  
  35. The standard doesn't define the result of converting a pointer to function
  36. to pointer to int (or any other data type).
  37.  
  38. >       ID            = 2;
  39. >    
  40. >>>     (*funct_ptr) (ID);
  41.  
  42. This syntax requires funct_ptr to be pointer to function, which it isn't,
  43. hence the compiler diagnostic.
  44.  
  45. >   }
  46. >   
  47. >   
  48. >   void test_entry_1(int ID)    {
  49.     ^^^^
  50. >       printf("Test entry 1 called, with ID of %2d\n", ID);
  51. >   }
  52.  
  53. Open your C book and learn how to declare a pointer to function.
  54. This is a too basic topic to be discussed in the newsgroup.
  55.  
  56. Dan
  57. -- 
  58. Dan Pop
  59. CERN, CN Division
  60. Email: danpop@mail.cern.ch 
  61. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  62.